/*
* blinkF.cpp
*
* Created on: 23-jan-2010
* Author: nrqm
* Modified From: main.cpp
* Modified By: fjmb
*/

#include "../arduinomega/WProgram.h"
#include "../arduinomega/Wire/Wire.h"
#include "../arduinomega/SoftwareSerial/SoftwareSerial.h"

#define LED 0x09 //default address of the LED according to the data sheet
#define BROADCAST 0x00
#define rxPin 0
#define txPin 1

int ledPin = 13; // LED connected to digital pin 13

extern "C" void __cxa_pure_virtual();

void setup();
void loop();

int main()
{
	// The init() function is defined in the Arduino library.
	// It initialises the timers and the ADC on the ATmega1280.
	init();
	setup();

	while( true )
	{
		loop();
	}

	return 0;
}

void __cxa_pure_virtual(){ while(true){digitalWrite(13, HIGH); delay( 200 ); digitalWrite(13, LOW); delay( 200 ); }};

void setup()
{
	/*writes S to serial for start
	 * then lets default script run for 2 seconds
	 * then sets led to red
	 * then delays two seconds
	 * then returns
	 */
	Serial.begin( 38400 );//set baud rate ... must be set in RealTerm as well
	Serial.write( 'S' );//write S to serial out for start

	delay( 2000 );//let default script run for two seconds
	Wire.begin(); // set up I2C
	Wire.beginTransmission( LED );// join I2C bus, to BlinkM
	Wire.send('o'); // stop the script
	Wire.endTransmission();//finish command

	Wire.beginTransmission(LED);// join I2C bus, to BlinkM
	Wire.send( 'n' );// set the colour without fading
	Wire.send(0xff);//set the colour to red
	Wire.send(0x00);
	Wire.send(0x00);
	Wire.endTransmission(); // finish command

	delay( 2000 );//wait 2 seconds
	Serial.write( 'E' );//print E for end to serial out
}
void loop()
{
	delay( 1000 );
}
